﻿@{
    ViewBag.Title = "UpdateCarInfo";
    ViewBag.First = "车辆管理";
    ViewBag.Second = "修改车辆基本信息";
    Layout = "~/Views/Shared/_BaseLayout.cshtml";
    var ent = ViewData["ent"] as Sc.Domain.CarInfo;
    var list = ViewData["type"] as IList<Sc.Domain.BaseItem>;
}
<script src="~/Content/laydate-v1.1/laydate/laydate.js"></script>
<script type="text/javascript">
    $(document).ready(function (e) {
        $("#selDriver").uedSelect({
            width: 247
        });
        $("#selCarType").uedSelect({
            width: 247
        });
        loadData();
        initSingleDate("txtBuyTime", "YYYY-MM-DD");
        $("#selCarType").val('@ent.CarType');
        $("#selCarType").prev().find("em[class=uew-select-text]").text(CarTypeName);
    });
    //加载驾驶员
    function loadData() {
        var url = '@Url.Action("GetDriver")';
        var load = loadTip("驾驶员加载中，请稍候", 16, 0);
        $.get(url, function (data) {
            if (data.length > 0) {
                var sel = document.getElementById("selDriver");
                $.each(data, function (index, n) {
                    var option = document.createElement("option");
                    option.text = n.Name;
                    option.value = n.Id;
                    sel.appendChild(option);
                });
                $("#selDriver").prev().find("em[class=uew-select-text]").text('@ent.DriverName');
                $("#selDriver").val(@ent.Driver);
                $("#selCarType").prev().find("em[class=uew-select-text]").text('@ent.CarTypeName');
                $("#selCarType").val(@ent.CarType);
            }
            layer.close(load);
        });
    }
    //数据保存
    function Save() {
        var txtCarNo = $("#txtCarNo").val();
        var selDriver = $("#selDriver").val();
        var txtCount = $("#txtCount").val();
        var txtUserRange = $("#txtUserRange").val();
        var selCarType = $("#selCarType").val();
        var txtFile = $("#txtFile").val();
        if (txtCarNo.length <= 0) {
            Tips("车牌号不能为空", "txtCarNo");
            return false;
        }
        if (selDriver.length <= 0) {
            Tips("请确定一个驾驶员", "selDriver");
            return false;
        }
        if (txtCount.length <= 0) {
            Tips("请输入准载人数", "txtCount");
            return false;
        }
        if (selCarType.length <= 0) {
            Tips("请选择车辆类型", "selCarType");
            return false;
        }
        if (txtFile.length <= 0) {
            Tips("请上传一张车辆图片", "txtFile");
            return false;
        }
        var url = '@Url.Action("SaveCarInfo")?' + $("#formData").serialize() + "&Driver=" + selDriver + "&CarType=" + selCarType;
        var load = loadTip('数据提交中，请稍后', 16, 0);
        $.ajaxFileUpload({
            url: url,
            secureuri: false,
            fileElementId: 'j',
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data > 0) {
                    layer.msg('车辆信息修改成功', { icon: 1, time: 1000, shade: [0.3, '#000'] }, function () {
                        layer.closeAll();
                        back();
                    });
                }
            }
        });
    }
    //返回
    function back() {
        window.location.href = "@Url.Action("Index")";
    }
</script>
<style type="text/css">
    b {
        color: #d70101;
        margin-left: 2px;
    }
</style>
<div class="place" style="padding:2px;">
    <input type="button" name="button" class="btn82 btn_save2" value="保存" onclick="Save();">
    <input type="button" name="button" class="btn82 btn_res" value="返回" onclick="back();">
</div>
<div class="formbody">
    <div class="formtitle"><span>车辆基本信息</span></div>
    <form method="post" enctype="multipart/form-data" class="jqtransform" id="formData">
        <input type="hidden" value="@ent.Id" name="Id" />
        <table style="width:98%;margin-left:20px;line-height:48px;">
            <tr>
                <td><label>车牌号</label><b>*</b></td>
                <td><input name="CarNo" type="text" class="dfinput" value="@ent.CarNo" id="txtCarNo" /></td>
                <td><label>驾驶员</label><b>*</b></td>
                <td>
                    <select name="select" class="select2" id="selDriver"></select>
                </td>
            </tr>
            <tr>
                <td><label>准载人数</label><b>*</b></td>
                <td><input name="TakeCount" type="text" class="dfinput" value="@ent.TakeCount" id="txtCount" /></td>
                <td><label>使用范围</label><b>*</b></td>
                <td><input name="UseRange" type="text" class="dfinput" value="@ent.UseRange" id="txtUserRange" /></td>
            </tr>
            <tr>
                <td><label>车型</label><b>*</b></td>
                <td>
                    <select name="select" class="select2" id="selCarType">
                        <option value="-1">--------请选择--------</option>
                        @foreach (var item in list)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>
                </td>
                <td><label>车架号</label></td>
                <td><input name="ChassisNumber" type="text" class="dfinput" value="@ent.ChassisNumber" /></td>
            </tr>
            <tr>
                <td><label>车颜色</label></td>
                <td><input name="CarColor" type="text" class="dfinput" value="@ent.CarColor" /></td>
                <td><label>排量</label></td>
                <td><input name="CarDisplacement" type="text" class="dfinput" value="@ent.CarDisplacement" /></td>
            </tr>
            <tr>
                <td><label>初始里程</label></td>
                <td><input name="StarMileage" type="text" class="dfinput" value="@ent.StarMileage" /></td>
                <td><label>保养时段</label></td>
                <td><input name="Maintenance" type="text" class="dfinput" value="@ent.Maintenance" /></td>
            </tr>
            <tr>
                <td><label>准载吨位</label><b>*</b></td>
                <td><input name="ZcTonnage" type="text" class="dfinput" id="txtZcTonnage" value="@ent.ZcTonnage" /></td>
                <td><label>报废年限</label><b>*</b></td>
                <td><input name="ServiceLife" type="text" class="dfinput" id="txtServiceLife" value="@ent.ServiceLife" /></td>
            </tr>
            <tr>
                <td><label>购买日期</label><b>*</b></td>
                <td><input name="BuyTime" type="text" readonly="readonly" class="dfinput" id="txtBuyTime" value="@ent.BuyTime.ToString("yyyy-MM-dd")" /></td>
                <td><label>车辆图片</label><b></b></td>
                <td>
                    <input type="file" onchange="ye.value=value" style="display:none;" name="j" id="j" class="input-text">
                    <input type="text" name="ye" value="@ent.ImageUrl" class="dfinput" readonly="readonly" id="txtFile">
                    <input type="button" style="background: #e7e7e7; cursor: pointer; color: #333; font-weight: normal; height: 32px; line-height: normal; width: 55px; border-color: #e7e7e7;" onclick="j.click()" value="浏览">
                </td>
            </tr>
        </table>
    </form>
</div>
